/*
 * Copyright 1999-2011 Alibaba Group.
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.dubbo.common.io;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

/**
 * UnsafeByteArrayOutputStream.
 * 
 * @author qian.lei
 */

public abstract class ByteArrayOutputStream extends OutputStream{
	static public final byte[]ZERO = new byte[0];

	abstract public void ensureIncreaseCapacity(int len);
	abstract public void ensureCapacity(int len);
	abstract public void write(int b);
	abstract public void write(byte b[], int off, int len);
	abstract public int size();
	abstract public void reset();
	abstract public byte[] toByteArray();
	abstract public ByteBuffer toByteBuffer();

	abstract public void writeTo(OutputStream out) throws IOException;
	abstract public ByteArray detach();
	abstract public String toString(String charset) throws UnsupportedEncodingException;
	
	abstract public void writeInt8(byte b); 
	abstract public void writeInt8(int b);
	abstract public void writeInt8(int index, byte b);
	abstract public void writeInt32b(int b);
	abstract public void writeInt32b(int index, int b);
	
	abstract public void writeInt16b(short b);
	abstract public void writeInt16b(int index, short b);
	
	abstract public void writeInt64b(int index, long b);
	abstract public void writeInt64b( long b);

	abstract public void close() throws IOException;
}